PROJECT( laguna-gt )

cmake_minimum_required( VERSION 2.8 )

set( LGT_SERIAL "/dev/ttyACM0" CACHE STRING "tty of the board" )
set( LGT_SERIAL_BAUD "115200" CACHE STRING "baudrate of the tty" )
set( LGT_CORE "atmega328p" CACHE STRING "Core used for laguna-gt compilation" )

message( "-- using serial line : ${LGT_SERIAL}" )
message( "-- using serial baudrate : ${LGT_SERIAL_BAUD}" )

set( CMAKE_C_COMPILER "avr-g++" )
set( CMAKE_C_FLAGS "-mmcu=atmega328p -I${CMAKE_SOURCE_DIR}")
set( CMAKE_SHARED_LIBRARY_LINK_C_FLAGS )

file( GLOB_RECURSE
      source_bsp
      ${CMAKE_SOURCE_DIR}/BSP/atmega328p.cpp)

file( GLOB_RECURSE
      source_lag
      ${CMAKE_SOURCE_DIR}/hw/led.cpp
      ${CMAKE_SOURCE_DIR}/main.cpp
      ${CMAKE_SOURCE_DIR}/locore.s)

set_source_files_properties(${source_bsp} ${source_lag} PROPERTIES LANGUAGE C)

add_definitions( "-D${LGT_CORE}" )

add_executable( laguna-gt ${source_bsp} ${source_lag} )

add_custom_target( objcopy ALL "avr-objcopy" -O "ihex" -R ".eeprom" "laguna-gt" "laguna-gt.hex" DEPENDS laguna-gt )
add_custom_target( program "avrdude" -v -v -v -v -F -p ${LGT_CORE} -c "arduino" -P ${LGT_SERIAL} -b ${LGT_SERIAL_BAUD} -D -U "flash:w:laguna-gt.hex:i" DEPENDS objcopy )

set_directory_properties( PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_BINARY_DIR}/laguna-gt.hex" )